import string
from collections import Counter

text = "Python is a 2000 made-for-TV horror movie directed by Richard \
Clabaugh. The film features several cult favorite actors, including William \
Zabka of The Karate Kid fame, Wil Wheaton, Casper Van Dien, Jenny McCarthy, \
Keith Coogan, Robert Englund (best known for his role as Freddy Krueger in the \
A Nightmare on Elm Street series of films), Dana Barron, David Bowe, and Sean \
Whalen. The film concerns a genetically engineered snake, a python, that \
escapes and unleashes itself on a small town. It includes the classic final\
girl scenario evident in films like Friday the 13th. It was filmed in Los Angeles, \
 California and Malibu, California. Python was followed by two sequels: Python \
 II (2002) and Boa vs. Python (2004), both also made-for-TV films."

text2 = "hello,i am your father! i am fine"

# 拆分文本，剔除标点
def get_tokens(text):
    text = text.lower()
    for word in text:
        if word in string.punctuation:
            text = text.replace(word, " ")
    text = text.split(" ")
    return text

def tf(word, count):
    # 统计词频，需要知道词的个数以及text的总词数
    return count[word] / sum(count.values())


counter =Counter(get_tokens(text2))
for word in counter:
    print(word, " :", tf(word, counter))